package com.bw.shop_2302.fg

import androidx.lifecycle.viewModelScope
import com.bw.base.entity.GoodsEntity
import com.bw.base.entity.IndexEntity
import com.bw.base.entity.Res
import com.bw.base.mvvm.BaseViewModel
import com.bw.shop_2302.utils.SingleLiveData
import kotlinx.coroutines.launch

class HomeViewModel:BaseViewModel() {

    //首页数据
    var indexsuccess=SingleLiveData<Res<IndexEntity>>()
    var indexfail=SingleLiveData<String>()

    fun index(){
        viewModelScope.launch {

            try {

                indexsuccess.postValue(apiServer.Index())

            }catch (e:Exception){


                indexfail.postValue(e.message.toString())

            }

        }
    }

    var goodssuccess=SingleLiveData<Res<GoodsEntity>>()
    var goodsfail=SingleLiveData<String>()

    fun goods(type:Int,limit:Int,page:Int){
        viewModelScope.launch {

            try {

                goodssuccess.postValue(apiServer.Goods(type, limit, page))

            }catch (e:Exception){


                goodsfail.postValue(e.message.toString())


            }

        }
    }


}